package cn.fzhui.servlet;

import cn.fzhui.factory.ServiceFactory;
import cn.fzhui.service.StudentService;
import cn.fzhui.util.PageList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

public class PageListStudentServlet extends AuthServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        StudentService studentService = ServiceFactory.getStudentService();
        try {
            int currentPage = req.getParameter("currentPage") != null ? Integer.parseInt(req.getParameter("currentPage")) : 1;
            req.setAttribute("pageList", studentService.pageList(currentPage, req.getParameter("searchType"), req.getParameter("keyword")));
        } catch (SQLException exception) {
            exception.printStackTrace();
        }

        req.getRequestDispatcher("/index.jsp").forward(req, resp);
    }

    /**
     * 学生列表
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
